home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / OS / FWGraphx / Sources / FWGrObj.cpp < prev    next >
Encoding:
Text File  |  1994-04-21  |  4.3 KB  |  142 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWGrObj.cpp
  4. //    Release Version:    $ 1.0d1 $
  5. //
  6. //    Creation Date:        3/28/94
  7. //
  8. //    Copyright:    © 1993, 1994 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #ifndef FWGROBJ_H
  13. #include "FWGrObj.h"
  14. #endif
  15.  
  16. #ifndef FWDFAULT_H
  17. #include "FWDfault.h"
  18. #endif
  19.  
  20. // ----- OpenDoc Includes -----
  21.  
  22. #ifndef _EXCEPT_
  23. #include <Except.h>
  24. #endif
  25.  
  26. //==============================================================================
  27. //    •• RunTime Info
  28. //==============================================================================
  29.  
  30. #ifdef FW_BUILD_MAC
  31. #pragma segment fwgraphx
  32. #endif
  33.  
  34. //==============================================================================
  35. //    •• class FW_CGraphicObjectRep
  36. //==============================================================================
  37.  
  38. //------------------------------------------------------------------------------
  39. //    • FW_CGraphicObjectRep::FW_CGraphicObjectRep
  40. //------------------------------------------------------------------------------
  41.  
  42. FW_CGraphicObjectRep::FW_CGraphicObjectRep() :
  43.     fSeed(++gGraphicGlobales.gSeed),
  44.     fRefCount(0)
  45. {
  46. }
  47.  
  48. //------------------------------------------------------------------------------
  49. //    • FW_CGraphicObjectRep::~FW_CGraphicObjectRep
  50. //------------------------------------------------------------------------------
  51.  
  52. FW_CGraphicObjectRep::~FW_CGraphicObjectRep()
  53. {
  54. }
  55.  
  56. //------------------------------------------------------------------------------
  57. //    • FW_CGraphicObjectRep::Changed
  58. //------------------------------------------------------------------------------
  59.  
  60. void FW_CGraphicObjectRep::Changed()
  61. {
  62.     fSeed = ++gGraphicGlobales.gSeed;
  63. }
  64.  
  65. //==============================================================================
  66. //    •• class FW_CGraphicObjectPtr
  67. //==============================================================================
  68.  
  69. //----------------------------------------------------------------------------------------
  70. // FW_CGraphicObjectPtr::~FW_CGraphicObjectPtr
  71. //----------------------------------------------------------------------------------------
  72.  
  73. FW_CGraphicObjectPtr::~FW_CGraphicObjectPtr()
  74. {
  75.     DownCount();
  76. }
  77.  
  78. //----------------------------------------------------------------------------------------
  79. // FW_CGraphicObjectPtr::FW_CGraphicObjectPtr
  80. //----------------------------------------------------------------------------------------
  81.  
  82. FW_CGraphicObjectPtr::FW_CGraphicObjectPtr() :
  83.     fRep(NULL)
  84. {
  85. }
  86.  
  87. //----------------------------------------------------------------------------------------
  88. // FW_CGraphicObjectPtr::FW_CGraphicObjectPtr
  89. //----------------------------------------------------------------------------------------
  90.  
  91. FW_CGraphicObjectPtr::FW_CGraphicObjectPtr(const FW_CGraphicObjectPtr& other) :
  92.     fRep(other.fRep)
  93. {
  94.     UpCount();
  95. }
  96.  
  97. //----------------------------------------------------------------------------------------
  98. // FW_CGraphicObjectPtr::FW_CGraphicObjectPtr
  99. //----------------------------------------------------------------------------------------
  100.  
  101. FW_CGraphicObjectPtr::FW_CGraphicObjectPtr(FW_CGraphicObjectRep* rep) :
  102.     fRep(rep)
  103. {
  104.     UpCount();
  105. }
  106.  
  107. //----------------------------------------------------------------------------------------
  108. // FW_CGraphicObjectPtr::UpCount
  109. //----------------------------------------------------------------------------------------
  110.  
  111. void FW_CGraphicObjectPtr::UpCount()
  112. {
  113.     if (fRep)
  114.         fRep->IncrementRefCount();
  115. }
  116.  
  117. //----------------------------------------------------------------------------------------
  118. // FW_CGraphicObjectPtr::DownCount
  119. //----------------------------------------------------------------------------------------
  120.  
  121. void FW_CGraphicObjectPtr::DownCount()
  122. {    
  123.     if (fRep && !fRep->Release())
  124.         delete fRep;
  125.     // It is not necessary to set fRep to NULL. To see why, see how DownCount is used above.
  126.     // In all cases, fRep is either immediately reset, or the instance is being destroyed.
  127.     // Note too that DownCount is private.
  128. }
  129.  
  130. //----------------------------------------------------------------------------------------
  131. // FW_CGraphicObjectPtr::SetRep
  132. //----------------------------------------------------------------------------------------
  133.  
  134. void FW_CGraphicObjectPtr::SetRep(FW_CGraphicObjectRep* rep)
  135. {
  136.     if (fRep != rep)
  137.     {
  138.         DownCount();
  139.         fRep = rep;
  140.         UpCount();
  141.     }
  142. }